home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / sound / aiff writer sdev / componentdispatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  4.2 KB  |  143 lines

  1. /*
  2.     File:        ComponentDispatch.c
  3.  
  4.     Contains:    Common routines for dispatching for any sound component
  5.  
  6.     Written by: Mark Cookson    
  7.  
  8.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/16/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #ifndef __COMPONENTDISPATCH__
  25. #include "ComponentDispatch.h"
  26. #endif
  27.  
  28. #define DEBUG false
  29.  
  30. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. //    Sound Component Entry Point
  32. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33.  
  34. #if GENERATINGPOWERPC
  35. ProcInfoType __procinfo=uppSoundComponentEntryPointProcInfo;
  36. #endif
  37. pascal ComponentResult main(ComponentParameters *params, SoundComponentGlobalsPtr globals)
  38. {
  39.     ComponentResult                result;
  40.     short                        selector = params->what;
  41.  
  42. #if DEBUG
  43. DebugStr ("\pIn SoundComponentEntryPoint;g");
  44. #endif
  45.  
  46.     if (selector < 0)
  47.         switch (selector - kComponentRegisterSelect)    // standard component selectors
  48.         {
  49.             case kComponentRegisterSelect - kComponentRegisterSelect:
  50.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentRegister);
  51.                 break;
  52.  
  53.             case kComponentVersionSelect - kComponentRegisterSelect:
  54.                 return (kSoundComponentVersion);
  55.                 break;
  56.  
  57.             case kComponentCanDoSelect - kComponentRegisterSelect:
  58.                 result = __SoundComponentCanDo(0, *((short *) ¶ms->params[0]));
  59.                 break;
  60.  
  61.             case kComponentCloseSelect - kComponentRegisterSelect:
  62.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentClose);
  63.                 break;
  64.  
  65.             case kComponentOpenSelect - kComponentRegisterSelect:
  66.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentOpen);
  67.                 break;
  68.  
  69.             default:
  70.                 result = badComponentSelector;
  71.                 break;
  72.         }
  73.     else if (selector < kDelegatedSoundComponentSelectors)            // selectors that cannot be delegated
  74.         switch (selector)
  75.         {
  76.             case kSoundComponentInitOutputDeviceSelect:
  77.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __InitOutputDevice);
  78.                 break;
  79.  
  80.             default:
  81.                 result = badComponentSelector;
  82.                 break;
  83.         }
  84.     else                                                    // selectors that can be delegated
  85.         switch (selector)
  86.         {
  87.             case kSoundComponentGetInfoSelect:
  88.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentGetInfo);
  89.                 break;
  90.  
  91.             case kSoundComponentSetInfoSelect:
  92.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentSetInfo);
  93.                 break;
  94.  
  95.             case kSoundComponentStartSourceSelect:
  96.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __StartSource);
  97.                 break;
  98.  
  99.             case kSoundComponentPlaySourceBufferSelect:
  100.                 result = CallComponentFunctionWithStorageUniv((Handle) globals, params, __SoundComponentPlaySourceBuffer);
  101.                 break;
  102.  
  103.             default:
  104.                 result = DelegateComponentCall(params, globals->sourceComponent);
  105.                 break;
  106.         }
  107.  
  108.     return (result);
  109. }
  110.  
  111.  
  112. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. static pascal ComponentResult __SoundComponentCanDo(void *unused1, short selector)
  114. {
  115. #pragma unused (unused1)
  116.  
  117.     ComponentResult        result;
  118.  
  119.     switch (selector)
  120.     {
  121.         case kComponentRegisterSelect:
  122.         case kComponentVersionSelect:
  123.         case kComponentCanDoSelect:
  124.         case kComponentCloseSelect:
  125.         case kComponentOpenSelect:
  126.         case kSoundComponentInitOutputDeviceSelect:
  127.         // selectors that can be delegated
  128.         case kSoundComponentStartSourceSelect:
  129.         case kSoundComponentGetInfoSelect:
  130.         case kSoundComponentSetInfoSelect:
  131.         case kSoundComponentPlaySourceBufferSelect:
  132.             result = true;
  133.             break;
  134.  
  135.         default:
  136.             result = false;
  137.             break;
  138.     }
  139.  
  140.     return (result);
  141. }
  142.  
  143.